package BryantChad.LunchTimeScoreCard;

import java.io.Serializable;
import java.util.ArrayList;

public class CostabiPlayer extends AbstractPlayer implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public ArrayList<CostabiHand> Hands;
	
	public CostabiPlayer() {
		super();
		Hands = new ArrayList<CostabiHand>();
	}
	
	public CostabiPlayer(String name, ArrayList<CostabiHand> Hands) {
		super(name);
		this.Hands = Hands;
	}
	
	public int totalScore() {
		int score = 0;
		
		for (int round = 0; round < Hands.size(); round++) {
			score += handScore(Hands.get(round));
		}
		
		return score;
	}
	
	public int totalMadeBids() {
		int total = 0;

		for (int round = 0; round < Hands.size(); round++) {
			if (Hands.get(round).isMadeBid())
				total++;
		}
		
		return total;
	}
	
	public int totalMissedBids() {
		int total = 0;

		for (int round = 0; round < Hands.size(); round++) {
			if (!Hands.get(round).isMadeBid())
				total++;
		}
		
		return total;
	}
	
	private int handScore(CostabiHand hand) {
		
		if (hand.getTaken() < hand.getBid()) {
			return hand.getTaken(); 
		} else if(hand.getTaken() == hand.getBid()) {
			return  10 + (hand.getBid() * hand.getBid());
		} else {
			return 0;
		}
		
	}
}
